package leetcode.day_2021_3_1_2022_3_7;

import java.util.ArrayList;
import java.util.List;

/**
 * 46. 全排列
 * https://leetcode-cn.com/problems/permutations/
 */
public class LeetCode0046 {
    List<List<Integer>> res = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        solve(nums, new ArrayList<>());
        return res;
    }

    public void solve(int[] nums, List<Integer> list) {
        if (list.size() == nums.length) {
            res.add(new ArrayList<>(list));
            return;
        }

        for (int i=0; i<nums.length; i++) {
            if (list.contains(nums[i])) continue;
            list.add(nums[i]);
            solve(nums, list);
            list.remove(list.size()-1);
        }
    }
}
